package com.dns.framework.dao;

import java.util.Map;

/**
 * @author :  yulei
 * @data :  2018/7/6 16:35
 * @Version :  1.0
 **/

public class DaoHelper {


    /**
     * 获取总记录数的SQL
     * @param s
     * @return
     */
    public static String getCountSql(String s) throws Exception{
        StringBuffer sbf = new StringBuffer();
        sbf.append("SELECT COUNT(1) CNT FROM (");
        sbf.append(s);
        sbf.append(") m");

        String sf= sbf.toString();
        return  sf;
    }


    /**
     * 分页SQL
     * @param sql
     * @param map
     * @param start
     * @param end
     * @return
     * @throws Exception
     */
    public static String getPagingSql(String sql ,Map map,int start ,int end) throws Exception {
          StringBuffer str = new StringBuffer();

          str.append(sql);
          str.append(" LIMIT :START_INDEX,:NUM_PER_PAGE");
          //从哪行记录开始
          map.put("START_INDEX",start);
          //每页显示的记录数
          map.put("NUM_PER_PAGE", end);

          return str.toString();
    }

}
